//
//  THBabyOrderDetailViewController.m
//  TreeHole
//
//  Created by macbookpro on 2021/10/12.
//  Copyright © 2021 stoneobs. All rights reserved.
//

#import "THBabyOrderDetailViewController.h"
#import "THBabyDetailOrder.h"
@interface THBabyOrderDetailViewController ()
@property(nonatomic, strong)THBabyDetailOrder                      *detailModel;/**<  */
@end

@implementation THBabyOrderDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"订单详情";
    [self sendDetailRequest];
    // Do any additional setup after loading the view.
}
#pragma mark --configSubView
- (void)stoneobs_ui_configSubView{
    UIView * header = [UIView.alloc initWithFrame:STONEOBS_UI_UISCREEN_FRAME];
    header.backgroundColor = UIColor.whiteColor;
    
    CGFloat top = 20;
    
    ({
        
        UIImageView * stoneobs_ui_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, top, 60, 60)];
        [stoneobs_ui_imageView sd_setImageWithURL:self.detailModel.header_img.mj_url];
        [header addSubview:stoneobs_ui_imageView];
        stoneobs_ui_imageView.centerX = UISCREEN_WIDTH / 2;
        top = stoneobs_ui_imageView.bottom;
    });
    
    ({
        STButton * button = [self viewFormLeftTitle:@"订单信息" value:@""];
        button.top = top;
        top = button.bottom;
        [header addSubview:button];
        UILabel * lable = [button viewWithTag:10002];
        lable.text = @"订单信息";
        lable.textColor = UIColor.blackColor;
        lable.font = [UIFont fontWithName:STONEOBS_UI_FONT_CU_NAME size:18];
        lable.width = 200;
    });
    ({

        STButton * button = [self viewFormLeftTitle:@"订单编号" value:self.detailModel.nu];
        button.top = top;
        top = button.bottom;
        [header addSubview:button];
    });
    ({

        STButton * button = [self viewFormLeftTitle:@"订单状态" value:self.detailModel.status_text];
        button.top = top;
        top = button.bottom;
        [header addSubview:button];
    });
    ({
        
        STButton * button = [self viewFormLeftTitle:@"下单时间" value:self.detailModel.created_at];
        button.top = top;
        top = button.bottom;
        [header addSubview:button];
    });
    ({
        
        STButton * button = [self viewFormLeftTitle:@"下单专业" value:self.detailModel.major];
        button.top = top;
        top = button.bottom;
        [header addSubview:button];
    });
    ({
        
        STButton * button = [self viewFormLeftTitle:@"专业年龄" value:self.detailModel.job_age];
        button.top = top;
        top = button.bottom;
        [header addSubview:button];
    });
    ({
        
        STButton * button = [self viewFormLeftTitle:@"专业价格" value:self.detailModel.price];
        button.top = top;
        top = button.bottom;
        [header addSubview:button];
    });
    
    ({
        
        STButton * button = [self viewFormLeftTitle:@"商家姓名" value:self.detailModel.real_name];
        button.top = top;
        top = button.bottom;
        [header addSubview:button];
    });
    ({
        
        STButton * button = [self viewFormLeftTitle:@"商家电话" value:self.detailModel.phone];
        button.top = top;
        top = button.bottom;
        [header addSubview:button];
    });
    
    
    ({
        STButton * button = [self viewFormLeftTitle:@"客户信息" value:@""];
        button.top = top+15;
        top = button.bottom;
        [header addSubview:button];
        UILabel * lable = [button viewWithTag:10002];
        lable.text = @"客户信息";
        lable.textColor = UIColor.blackColor;
        lable.font = [UIFont fontWithName:STONEOBS_UI_FONT_CU_NAME size:18];
        lable.width = 200;
    });
    
    ({
        
        STButton * button = [self viewFormLeftTitle:@"客户姓名" value:self.detailModel.user_name];
        button.top = top;
        top = button.bottom;
        [header addSubview:button];
    });
    ({
        
        STButton * button = [self viewFormLeftTitle:@"客户联系方式" value:self.detailModel.user_phone];
        button.top = top;
        top = button.bottom;
        [header addSubview:button];
    });
    ({
        
        STButton * button = [self viewFormLeftTitle:@"服务地址" value:self.detailModel.address];
        button.top = top;
        top = button.bottom;
        [header addSubview:button];
    });
    ({
        
        STButton * button = [self viewFormLeftTitle:@"服务时间" value:self.detailModel.service_at];
        button.top = top;
        top = button.bottom;
        [header addSubview:button];
    });
    
    

    
    
    ({
        STButton * button = [self viewFormLeftTitle:@"服务二维码" value:@""];
        button.top = top+15;
        top = button.bottom;
        [header addSubview:button];
        UILabel * lable = [button viewWithTag:10002];
        lable.text = @"服务二维码";
        lable.textColor = UIColor.blackColor;
        lable.font = [UIFont fontWithName:STONEOBS_UI_FONT_CU_NAME size:18];
        lable.width = 200;
        
    });
    
    ({
        
        UIImageView * stoneobs_ui_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, top, 280, 280)];
        [stoneobs_ui_imageView sd_setImageWithURL:self.detailModel.code_url.mj_url];
        [header addSubview:stoneobs_ui_imageView];
        stoneobs_ui_imageView.centerX = UISCREEN_WIDTH / 2;
        top = stoneobs_ui_imageView.bottom;
    });
    
    header.height = top;
    self.tableView.tableHeaderView = header;
    
}

- (STButton*)viewFormLeftTitle:(NSString*)leftTitle value:(NSString*)value{
    STButton * view  = [[STButton alloc] initWithFrame:CGRectMake(0, 0, STONEOBS_UI_UISCREEN_WIDTH, 35)
                                                 title:nil
                                            titleColor:nil
                                             titleFont:0
                                          cornerRadius:0
                                       backgroundColor:nil
                                       backgroundImage:nil
                                                 image:nil];
    
    
    STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(17, 0, 120, view.height)
                                                            text:[NSString stringWithFormat:@"%@:",leftTitle]
                                                       textColor:STMC_UICOLOR_FROM_RGBA(0x343434)
                                                            font:14
                                                     isSizetoFit:NO
                                                   textAlignment:NSTextAlignmentLeft];
    [view addSubview:stoneobs_ui_label];
    [NSString stoneobs_fun_lableAutoAdjustWitdhWithLabel:stoneobs_ui_label];
    stoneobs_ui_label.tag = 10002;
    
    STLabel * stoneobs_ui_s_label = [[STLabel alloc] initWithFrame:CGRectMake(stoneobs_ui_label.right, 0, STONEOBS_UI_UISCREEN_WIDTH -stoneobs_ui_label.right - 20 , view.height)
                                                              text:value
                                                         textColor:STMC_UICOLOR_FROM_RGBA(0x343434)
                                                              font:14
                                                       isSizetoFit:NO
                                                     textAlignment:NSTextAlignmentLeft];
    [view addSubview:stoneobs_ui_s_label];
    [NSString stoneobs_fun_lableAutoAdjustheightWithLabel:stoneobs_ui_s_label];
    if (stoneobs_ui_s_label.height < view.height) {
        stoneobs_ui_s_label.height = view.height;
    }else{
        view.height = stoneobs_ui_s_label.height + 20;
    }
    stoneobs_ui_label.centerY = view.height/2;
    stoneobs_ui_s_label.centerY = view.height/2;
    stoneobs_ui_s_label.tag = 10001;
    UIView * stoneobs_ui_line = [[UIView alloc] initWithFrame:CGRectMake(17, view.height - 0.5, STONEOBS_UI_UISCREEN_WIDTH, 5)];
    stoneobs_ui_line.backgroundColor = self.tableView.backgroundColor;
    //    [view addSubview:stoneobs_ui_line];
    __weak typeof(self) weakSelf =  self;
    return view;
    
}
- (void)sendDetailRequest{
    NSMutableDictionary * stoneobs_net_param_dic = [NSMutableDictionary new];
    NSString * stoneobs_net_user_id = [STTools_UserManger defult].stoneobs_fun_get_loginedUser.uid.description;
    NSString * stoneobs_net_user_token = STTools_UserManger.defult.stoneobs_fun_get_loginedUser.token;
    if (stoneobs_net_user_id.length) {
        [stoneobs_net_param_dic setObject:stoneobs_net_user_id forKey:@"uid"];
    }
    if (stoneobs_net_user_token.length) {
        [stoneobs_net_param_dic setObject:stoneobs_net_user_token forKey:@"token"];
    }
    if (self.easyModel.o_id.length ) {
        [stoneobs_net_param_dic setObject:self.easyModel.o_id forKey:@"id"];
    }
    NSString * stoneobs_net_net_url = [NSString stringWithFormat:@"%@%@",RELEASE_SERVER_URL_HEADER,@"v1/nursery/orderDetail"];
    DDLogInfo(@"url:%@",stoneobs_net_net_url);
    DDLogInfo(@"param:%@",stoneobs_net_param_dic);
    [[STTools_NetWrokManger defaultClient] stoneobs_fun_requestWithPath:stoneobs_net_net_url
                                                                 method:STHttpRequestType_stoneobs_enumGet
                                                             parameters:stoneobs_net_param_dic
                                                                success:^(NSURLSessionDataTask *operation, id responseObject) {
        [SVProgressHUD dismiss];
        NSDictionary * dataDic = responseObject[@"data"];
        self.detailModel = [THBabyDetailOrder mj_objectWithKeyValues:dataDic];
        [self stoneobs_ui_configSubView];
        // DDLogInfo(@"json = \n%@",modelDic.mj_JSONString);
        DDLogInfo(@"%@请求成功:resp\n%@",stoneobs_net_net_url,responseObject);
        
        
    } failure:^(NSString *stateCode, STTools_Error *error,NSError *originError) {

        DDLogError(@"\n请求失败:\nurl:%@\nparam:%@\n失败原因:%@\n错误码:%ld",
                   stoneobs_net_net_url,stoneobs_net_param_dic,error.desc,error.code);
    }];
    
}
@end
